package com.lakeworks.web.controller.core;

import com.lakeworks.common.annotation.Anonymous;
import com.lakeworks.common.annotation.RepeatSubmit;
import com.lakeworks.common.annotation.RoleAnnotation;
import com.lakeworks.common.core.controller.BaseController;
import com.lakeworks.common.core.domain.AjaxResult;
import com.lakeworks.common.enums.UserRoleType;
import com.lakeworks.domain.ChannelInfo;
import com.lakeworks.domain.SysChannel;
import com.lakeworks.service.ISysChannelAuthService;
import com.lakeworks.service.ISysChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 三方渠道信息Controller
 *
 * @author lake
 * @date 2023-02-08
 */
@RestController
@RequestMapping("/system")
public class SysChannelController extends BaseController {
    @Autowired
    private ISysChannelService sysChannelService;

    @Autowired
    private ISysChannelAuthService channelAuthService;

    @PostMapping("/channel")
    //@Anonymous
    @RoleAnnotation(UserRoleType.GLRY)
    @RepeatSubmit
    public AjaxResult addChannel(@Valid @RequestBody ChannelInfo channelInfo){return sysChannelService.addChannel(channelInfo);}

    @GetMapping("/channels")
    public AjaxResult list() {
        return success(sysChannelService.selectSysChannelList(new SysChannel()));
    }


    @PatchMapping("/channel")
    //@Anonymous
    @RoleAnnotation(UserRoleType.GLRY)
    public AjaxResult updateChannel(@RequestBody ChannelInfo channelInfo){return sysChannelService.updateChannel(channelInfo);}


    @GetMapping("/channel/{id}")
    public AjaxResult getChannelById(@PathVariable Long id) {
        return success(sysChannelService.selectSysChannelById(id));
    }


    @GetMapping("/channel/auth/id/{id}")
    public AjaxResult getAuthById(@PathVariable Long id) {
        return success(channelAuthService.selectByChannelId(id));
    }

    @GetMapping("/channel/auth/ak/{ak}")
    public AjaxResult getAuthByAk(@PathVariable String ak) {
        return success(channelAuthService.selectByAk(ak));
    }
}
